import 'package:fakegpt/api/ChatGptApi.dart';
import 'package:fakegpt/page/chat/state.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';

class ChatLogic extends GetxController {
  ChatState state = ChatState();
  @override
  void onInit() {
    super.onInit();
    print("获取历史消息");
    getHistory();
  }

  void send() {
    if (state.textController.text.isEmpty) return;
  }

  Future<void> getHistory() async {
    state.list.clear();
    EasyLoading.show(status: "获取历史消息");
    try {
      state.list.addAll(await ChatGptApi.getHistory("${Get.arguments}"));
    } catch (e) {
      Get.snackbar("提示", "获取历史消息失败");
    }
    EasyLoading.dismiss();
    update(['list']);
  }
}
